// var IP = 'http://192.168.102.53:5005';
var totalNum;
var psize = 15;
var pnum = 1;
$(function () {
    // 加载页面时 渲染
    $.ajax({
        type: "get",
        // url: IP + "/find-list",
        url: "/find-list",
        dataType: "json",
        data: {
            psize: psize,
            pnum: pnum
        },
        success: function (data) {
            showList(data.data);
            // 分页
            $('#pagination').pagination({
                totalData: data.totalNum,
                showData: psize,
                coping: true,
                callback: function (i) {
                    var pnum = i;
                    // 点击页数时，请求列表数据
                    $.ajax({
                        type: "get",
                        // url: IP + "/find-list",
                        url: "/find-list",
                        dataType: "json",
                        data: {
                            psize: psize,
                            pnum: pnum
                        },
                        success: function (data) {
                            showList(data.data);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            console.log('请求失败!');
                        }
                    })
                }
            }, function (api) {

            });
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log('请求失败!');
        }
    })

    // 遍历列表
    function showList(data) {
        $('#scoLists_ul').html("");
        var scoreList = "";
        for (var i = 0; i < data.length; i++) {
            scoreList += '<li class="fixed">';
            scoreList += '<span class="scoList_tt">' + data[i].name + '</span>';
            scoreList += '<span class="scoList_hospital">';
            if(data[i].type == 1 ||data[i].type == 2||data[i].type == 3||data[i].type == 4||data[i].type == 7){
                scoreList += '浙江大学附属第一医院';
            }
            if(data[i].type == 6){
                scoreList += '华中科技大学同济医学院附属协和医院';
            }
            scoreList += '</span>';
            scoreList += '<span class="scoList_check"><a href="javascript:;" toId="' + data[i].id + '" toType="' + data[i].type + '">查看</a></span>';
            scoreList += '</li>';
        }
        $('#scoLists_ul').html(scoreList);

        $('.scoList_check>a').click(function () {
            console.log('a');
            var toId = $(this).attr('toId');
            var toType = $(this).attr('toType');
            window.location.href = '/details.html?id=' + toId + '&type=' + toType;
        })
    }


    // $('#pagination').pagination({
    //     totalData: 100,
    //     showData: 10,
    //     coping: true,
    //     callback: function (i) {
    //         console.log(i)

    //     }
    // }, function (api) {
    //     $('#logBox').append('<p>*当前页码为：' + api.getCurrent() + '</p>');
    //     $('#logBox').append('<p>*当前总页数：' + api.getTotalPage() + '</p>')
    // });

})